﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Pavilion
{
    public class PolygonPhysicalData : PhysicalData
    {
        public override Vector2 Origin { get { return base.Origin; } set { updatePhysicalFormChanged = false; base.Origin = value; PhysicalBounds.Origin = value; updatePhysicalFormChanged = true; } }
        public override bool IsFlippedHorizontally { get { return base.IsFlippedHorizontally; } set { PhysicalBounds.IsHorizontallyFlipped = value; base.IsFlippedHorizontally = value; } }
        public PolygonBox PhysicalBounds { get; private set; }

        private bool updatePhysicalFormChanged = true;

        public PolygonPhysicalData(GameToolBase parentGameTool) : base(parentGameTool)
        {
            PhysicalBounds = new PolygonBox();
            PhysicalBounds.PolygonBoxChanged += (box) => { if (updatePhysicalFormChanged) OnPhysicalFormChanged(); };
        }

        public override void SetPosition(float x, float y)
        {
            Vector2 newPosition = new Vector2(x, y);
            Vector2 distance = newPosition - Position;

            if (distance == default(Vector2))
                return;

            updatePhysicalFormChanged = false;
            PhysicalBounds.Position = newPosition;
            updatePhysicalFormChanged = true;

            base.SetPosition(x, y);
        }
    }
}
